<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page isELIgnored ="false" %>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
	<meta charset="UTF-8">
    <title>账号管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">开户行</div>
                <div class="field">
                    <input name="bkNm" id="bkNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">账号名称</div>
                <div class="field">
                    <input name="accNm1" id="accNm1" type="text" class="ui-textbox" value="">
                </div>
            </div>
           
            
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                <!-- <span id="detailBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_2"></i>详细</span> -->
                <span id="addBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_3"></i>新增账号</span>
                <%--<span id="downloadBtn" class="sq-button sq-button-hasicon" onclick="exportBkAcc();"><i class="sqBtnIco_21"></i>导出</span>--%>
                <span id="" class="sq-button sq-button-hasicon" onclick="loadFlow()"><i class="sqBtnIco_40"></i>流程信息</span>
               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>
<!-- 增加账号弹出框 -->
<div id="addAcc_Html" style="display:none">
    
</div>

<!-- 修改账号弹出框 -->
<div id="changeAcc_Html" style="display:none">
    <form id="changeAcc_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100">
                <div class="label">类型</div>
                <div class="field">
                    <span name="accTypNm" id="accTypNm">&nbsp;</span>
                    
                    <input name="accTypCd" id="accTypCd" type="hidden" value="">
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">开户行</div>
                <div class="field">
                    <span name="bkNm" id="bkNmC">&nbsp;</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">账号名称</div>
                <div class="field">
                    <input name="accNm" id="accNm" type="text" class="ui-textbox" value="" validate="{required:true}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">账号</div>
                <div class="field">
                    <input name="accNo" id="accNo" type="text" class="ui-textbox" value="" validate="{required:true}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100" >
                <div class="label">支持平台</div>
                <div class="field">
                  	<c:forEach items="${sysOrgList }" var="item" begin="0" step="1" varStatus="status">
                        	<input type="checkbox" orgcd="${item.orgCd }" orgid="${item.id }" value="${item.id }" name="orgIds" />${item.orgNm }<br/>	
                  	</c:forEach>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">账户备注</div>
                <div class="field">
                    <input name="accRem" id="accRem" type="text" class="ui-textbox" value="">
                </div>
            </div>
           <div class="fieldBox col_100">
                <div class="label">付款帐号主体</div>
                <div class="field">
                	
                    <select name="payerMainCd" id="payerMainCd" data-value=" " validate="{required:true,select:true}">
                       <option value=" ">请选择</option>
                       <c:forEach items="${payerMainCdList }" var="item">
                     		<option value="${item.key }">${item.value}</option>
                     		
                       </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveChangeAcc_Btn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
</div>

<script type="text/javascript">
	var grid = null;
	var addBankData_s={

	}
	$(function () {
		var _bkId = '${bkId}';
		var _url;
		if(_bkId){
			_url = '<%=path%>/system/sysBkAccInfo/initList.do?bkId='+_bkId ;
		}else{
			_url = '<%=path%>/system/sysBkAccInfo/initList.do';
		}
	    grid = $("#ligergrid1").ligerGrid({
	    	url:_url ,
	    	method : 'get',
	        columns: [
	            { display: '开户行', name: 'bkNm', width: 250},
	            { display: '账户名称', name: 'accNm', width: 250, enabledSort:true},
	            { display: '账号', name: 'accNo', width: 250, enabledSort:true},
	            { display: '账号类型', name: 'accTypNm', minWidth: 100, enabledSort:true},
	            { display: '状态', name: 'isOpen', minWidth: 100 , enabledSort:true},
	            { display: '账号备注', name: 'accRem', minWidth: 140, enabledSort:true},
	            { display: '付款帐号主体', name: 'payerMainNm', minWidth: 200, enabledSort:true},
	            { display: '审核状态', name: 'audStsCd', minWidth: 140, enabledSort:true,
	            	render:function(item){
	            		if(item.audStsCd=='0'){
	            			return "已保存";
	            		}else if(item.audStsCd=='1'){
	            			return "审核中";
	            		}else if(item.audStsCd=='2'){
	            			return "审核通过";
	            		}else if(item.audStsCd=='3'){
	            			return "审核不通过";
	            		}
	            	}
	            },
	            { display: '操作', width: 200 ,align:'left',
					render: function (rowdata, rowindex, value){
	            		var v;
	                    var v1='<a class="sq-button-hasicon" href="javascript:;" onclick="disable(';
	                        v1+="'"+rowdata.id+"'";
	                        v1+=')"><i class="sqBtnIco_13"></i>'+LogUtils.LOG_CMM_GRID_BTN_DISABLE+'</a>';
	                        
	                    var v2='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
	                        v2+="'"+rowdata.id+"'";
	                        v2+=')"><i class="sqBtnIco_12"></i>'+LogUtils.LOG_CMM_GRID_BTN_ENABLE+'</a>';
	                	switch (rowdata.isValid){
	                       case 0:
	                           v=v2;
	                           break;
	                       case 1:
	                           v=v1;
	                           break;
	                       default:
	                       	v=v1;
	                       	break;
	                    }
	            		var h='<a class="sq-button-hasicon" href="javascript:toMfrModify(';
		            		h+="'"+rowdata.id+"'";
		                    h+=')"><i class="sqBtnIco_4"></i>修改</a>';
	            		var d='<a class="sq-button-hasicon" href="javascript:deleteRecord(';
		            		d+="'"+rowdata.id+"'";
		                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
		                 if(rowdata.audStsCd=='1' || rowdata.audStsCd=='2' ){//审核中  审核通过
		                 } else{
		                	d='<a class="sq-button-hasicon" href="javascript:startFlowAcc(';
		            		d+="'"+rowdata.id+"'";
		                    d+=')"><i class="sqBtnIco_29"></i>审核</a>';
		                 }
	                	return v + h + d;
	            	}	
				},
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        checkbox:true,
	        rownumbers:true,
	        allowUnSelectRow:true,
	        alternatingRow: false,
	    });
	    grid.setHeight(100);
	
	    $("#searchBar").ligerForm();
	
	    $("#pageloading").hide();
	    
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	         
	        grid = $("#ligergrid1").ligerGrid({
		    	url:'<%=path%>/system/sysBkAccInfo/initList.do' ,
		    	method : 'get',
		        columns: [
		            { display: '开户行', name: 'bkNm', width: 250},
		            { display: '账户名称', name: 'accNm', width: 250, enabledSort:true},
		            { display: '账号', name: 'accNo', width: 250, enabledSort:true},
		            { display: '账号类型', name: 'accTypNm', minWidth: 100, enabledSort:true},
		            { display: '状态', name: 'isOpen', minWidth: 100 , enabledSort:true},
		            { display: '账号备注', name: 'accRem', minWidth: 140, enabledSort:true},
		            { display: '付款帐号主体', name: 'payerMainNm', minWidth: 200, enabledSort:true},
		            { display: '审核状态', name: 'audStsCd', minWidth: 140, enabledSort:true,
		            	render:function(item){
		            		if(item.audStsCd=='0'){
		            			return "已保存";
		            		}else if(item.audStsCd=='1'){
		            			return "审核中";
		            		}else if(item.audStsCd=='2'){
		            			return "审核通过";
		            		}else if(item.audStsCd=='3'){
		            			return "审核不通过";
		            		}
		            	}
		            },
		            { display: '操作', width: 200 ,align:'left',
						render: function (rowdata, rowindex, value){
		            		var v;
		                    var v1='<a class="sq-button-hasicon" href="javascript:;" onclick="disable(';
		                        v1+="'"+rowdata.id+"'";
		                        v1+=')"><i class="sqBtnIco_13"></i>'+LogUtils.LOG_CMM_GRID_BTN_DISABLE+'</a>';
		                        
		                    var v2='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
		                        v2+="'"+rowdata.id+"'";
		                        v2+=')"><i class="sqBtnIco_12"></i>'+LogUtils.LOG_CMM_GRID_BTN_ENABLE+'</a>';
		                	switch (rowdata.isValid){
		                       case 0:
		                           v=v2;
		                           break;
		                       case 1:
		                           v=v1;
		                           break;
		                       default:
		                       	v=v1;
		                       	break;
		                    }
		            		var h='<a class="sq-button-hasicon" href="javascript:toMfrModify(';
			            		h+="'"+rowdata.id+"'";
			                    h+=')"><i class="sqBtnIco_4"></i>修改</a>';
		            		var d='<a class="sq-button-hasicon" href="javascript:deleteRecord(';
			            		d+="'"+rowdata.id+"'";
			                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
			               if(rowdata.audStsCd=='1' || rowdata.audStsCd=='2' ){//审核中  审核通过
				            } else{
			                	d='<a class="sq-button-hasicon" href="javascript:startFlowAcc(';
			            		d+="'"+rowdata.id+"'";
			                    d+=')"><i class="sqBtnIco_29"></i>审核</a>';
				            }   
		                	return v + h + d;
		            	}	
					},
		        ],
		        pageSize:10,
		        root:'rows',
		        record:'total',
		        hideLoadButton : true,
		        width: '100%',
		        isScroll: false,
		        //checkbox:true,
		        rownumbers:true,
		        allowUnSelectRow:true,
		        alternatingRow: false,
		    });
	        
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	    });
	
	    $("#addBtn").click(function(event) {
			$.ligerDialog.open({
                //cls: 'noBorder_Dialog',
                width: 500,
                height:350,
                title : '新增账号',
                url:'<%=path%>/system/sysBkAccInfo/toAddPage.do'
            });
		});
	    
	    
	    /* 修改账号信息 */
	    $("#changeBtn").click(function(event) {
	    	var selectedRows = grid.getSelectedRows();
			if(selectedRows.length != 1){
				$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
				return;
			}
			var id = selectedRows[0].id;
	    	$.ajax({
				type: 'get',
				dataType:'json',
				data:{id:id},
				url: '<%=path%>/system/sysBkAccInfo/getById.do',
				success:function(msg){
					//alert("success...");
					if(msg.success == 1){
						//$.ligerDialog.success(msg.info)
						openChange();//弹出修改框
						setData(msg.data);//设置数据
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
	    	
	    });
	    $("#saveChangeAcc_Btn").click(function(event) {
	        var form = liger.get("changeAcc_form");
	        if (!form.valid()) {
	        	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
	            return false; 
	        }
	        var data = form.getData();
	        $.extend(true, data, addBankData_s); //合并要修改的账号信息(主键id,开户行id)
	        
	        //复选框数据
	        var _org = $('input:checkbox[name="orgIds"]:checked');
	        //var _orgIds = [];
	        var newJSON = {orgJSON:[]};
	        for(var i = 0; i < _org.length; i++){
	        	if(_org[i].checked){
	        		//_orgIds.push(_org[i].value);
	        		var org = '{orgId:"'+$(_org[i]).attr("orgid")+'",orgCd:"'+$(_org[i]).attr("orgcd")+'"}';
	        		newJSON.orgJSON.push(org);
	        	}
	        }
	        data["orgJSON"] = "["+newJSON.orgJSON+"]";

	        $.ligerDialog.hide();
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: '<%=path%>/system/sysBkAccInfo/modify.do',
				beforeSend:function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
					
					 
				}
			});
	    });
	    
	    
	    //删除
	    $("#delBtn").click(function(){
	    	deleteRecord();
	    });
	  
	    //启用
	    $("#openBtn").click(function(){
	   	 var selectedRows = grid.getSelectedRows();
	   		if(selectedRows.length != 1){
	   			$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
	   			return;
	   		}
	   		
	   	 	var id = selectedRows[0].id; 
		   	var _val = selectedRows[0].isOpen;
		   	 if(_val==LogUtils.LOG_CMM_GRID_BTN_ENABLE){
		   		$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_ENABLED_STATUS, SQ_type: "warning"});
	  			 return;
		   	 }
	   	
	   		$.ligerDialog.confirm(LogUtils.LOG_CMM_ENABLE_CONFIRM, function (flag) {
	   			if(flag == false)return;
	   			$.ajax({
	   				type: 'post',
	   				dataType:'json',
	   				data:{id:JSON.stringify(id)},
	   				url: '<%=path%>/system/sysBkAccInfo/enable.do',
	   				success:function(msg){
	   					 if(msg.success == 1){
	   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
	   						 grid.reload();
	   					 }else{
	   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
	   					 }
	   				}
	   			});
	   		});
	    });
	    //禁用
	    $("#closeBtn").click(function(){
	   	 var selectedRows = grid.getSelectedRows();
	   		if(selectedRows.length != 1){
	   			$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
	   			return;
	   		}
	   		
	   		var _val = selectedRows[0].isOpen;
		   	 if(_val==LogUtils.LOG_CMM_GRID_BTN_DISABLE){
		   		$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_DISABLED_STATUS, SQ_type: "warning"});
	   			return;
		   	 }
	   	 	var id = selectedRows[0].id; 
	   	
	   		
	   		$.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
	   			if(flag == false)return;
	   			$.ajax({
	   				type: 'post',
	   				dataType:'json',
	   				data:{id:id},
	   				url: '<%=path%>/system/sysBkAccInfo/disable.do',
	   				success:function(msg){
	   					 if(msg.success == 1){
	   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
	   						 grid.reload();
	   					 }else{
	   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
	   					 }
	   				}
	   			});
	   		});
	    });
	    
	    
});//----------------


//设置页面数据
function setData(data){
	//alert("setdate...");
	var form = new liger.get("changeAcc_form");
	addBankData_s.id=data.id;
	addBankData_s.bkId=data.bkId;
	addBankData_s.accTypCd=data.accTypCd;
	form.setData({
		accTypCd:data.accTypCd,
		accNm:data.accNm,
		accNo:data.accNo,
		accRem:data.accRem,
		payerMainCd:data.payerMainCd
		//orgIdsList:data.orgIdsList
	});
	$("#accTypNm").html(data.accTypNm);
	$("#bkNmC").html(data.bkNm);
	var _org = $('input:checkbox[name="orgIds"]');
    var _orgIds = data.orgIdsList;
    for(var i = 0; i<_org.length; i++){
    	_org_val=$(_org[i]).val();
    	if(_orgIds.indexOf((+_org_val))>=0){
    		$(_org[i]).ligerGetCheckBoxManager().setValue(true);
    	}
    }
	

} 

function openChange(){
	$.ligerDialog.open({
        width: 400,
        top: 100,
        title : '修改账号信息',
        target: $("#changeAcc_Html")
    });
	
	$("#changeAcc_form").ligerForm({validate: true});
}
//修改
function toMfrModify(id){
	if(!id)return;
	$.ajax({
		type: 'get',
		dataType:'json',
		data:{id:id},
		url: '<%=path%>/system/sysBkAccInfo/getById.do',
		success:function(msg){
			//alert("success...");
			if(msg.success == 1){
				//$.ligerDialog.success(msg.info)
				openChange();//弹出修改框
				setData(msg.data);//设置数据
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	});
}
//禁用
function disable(id){
	if(!id)return;
	$.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{id:id},
				url: '<%=path%>/system/sysBkAccInfo/disable.do',
				success:function(msg){
					 if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
}
//启用
function enable(id){
	if(!id)return;
	$.ligerDialog.confirm(LogUtils.LOG_CMM_ENABLE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{id:id},
				url: '<%=path%>/system/sysBkAccInfo/enable.do',
				success:function(msg){
					 if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
}
	
	
	//删除数据
	function deleteRecord(id){
		var _ids = [];
		if(!id){
			return;
		}else{
			_ids.push(id);
		}
		$.ligerDialog.confirm('确定删除吗?', function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/system/sysBkAccInfo/removeByIds.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: '删除中,请稍后...' ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						grid.reload();
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		});
	}
	//导出数据
	function exportBkAcc(){
		var selectedRows = grid.getSelectedRows();
		var _ids = [];
		
		for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		}
		$.ligerDialog.confirm('确定导出所选账号吗?未选中默认导出所有账号的信息.', function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'get',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/system/sysBkAccInfo/exportBkAcc.do',
				beforeSend:function(){
					wait_dialog=$.ligerDialog.SQalert({content: '正在导出账号信息...',SQ_type: "waitting"});
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						window.open(msg.data);
            			//$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				} 
			});
		});
	}
	
	function iframeResize () {
	    if (parent.mainApp && parent.mainApp.parentTab && parent.mainApp.parentTab.onResize) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//发起狮桥自有账户审核流程
	function startFlowAcc(_id){
		console.log(_id);
		if(!_id)return;
		var modelTyp ="R017";//流程业务分类-狮桥自有账户审核
		if(StringUtils.isEmpty(modelTyp)){
			console.log("modelTyp is null");
			return;
		}
    	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
		$.ajax({
    		type: 'post',
    		dataType:'json',
    		data:{
    			id:_id
    		},
    		url: '<%=path%>/system/sysBkAccInfo/addFlowStartOwnAccount.do',
			success : function(msg) {
				wait_dialog.close();
				//alert(msg.info);
				grid.reload();
				if (msg.success == 1) {
					UIUtils.alertSuccessHold1("下一节点操作人:李晨");
					//frameElement.dialog.close();
				} else {
					UIUtils.alertErrorHold1(msg.info);
				}
			}
		});
	}
	//狮桥自有账户-流程信息
	function loadFlow(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 800,
            height:500,
            title : '狮桥自有账户-流程信息',
            url:'<%=path%>/rfbase/fribaseinfo/toFriBaseFlow.do?id='+selectedRows[0].id,
        });
	}
</script>

</body>
</html>